//
//  TransModeViewController.m
//  CenturyInterconnection
//
//  Created by Tian Wei You on 16/5/13.
//  Copyright © 2016年 Shanghai DuRui Information Technology Company. All rights reserved.
//

#import "TransModeViewController.h"

@interface TransModeViewController ()<UITableViewDataSource,UITableViewDelegate>

@property(nonatomic,strong)UITableView *tableView;

@end

@implementation TransModeViewController

-(UITableView *)tableView{
    if (!_tableView) {
        _tableView=[[UITableView alloc]initWithFrame:CGRectMake(ACTUAL_HEIGHT(0),ACTUAL_HEIGHT(0), KScreenWidth, KScreenHeight) style:UITableViewStyleGrouped];
        _tableView.delegate=self;
        _tableView.dataSource=self;
    }
    return _tableView;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor=[UIColor whiteColor];
    [self makeNaviButton];
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"666"];
    [self.view addSubview:self.tableView];
}

-(void)makeNaviButton{
    
    self.title=@"SEND";
    
    UIButton *forkButton=[[UIButton alloc]initWithFrame:CGRectMake(ACTUAL_WIDTH(320), 0, ACTUAL_WIDTH(30), ACTUAL_HEIGHT(30))];
    [forkButton setImage:[UIImage imageNamed:@"nav_close"] forState:0];
    
    UIButton *leftButton = [UIButton buttonWithType:UIButtonTypeCustom];
    
    [leftButton setBackgroundImage:[UIImage imageNamed:@"nav_back"] forState:0];
    
    leftButton.frame=CGRectMake(0, 0, ACTUAL_WIDTH(23), ACTUAL_HEIGHT(23));
    //    forkButton.backgroundColor=[UIColor yellowColor];
    [forkButton addTarget:self action:@selector(comeBackToRoot) forControlEvents:UIControlEventTouchUpInside];
    [leftButton addTarget:self action:@selector(comeBack) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem*item1 = [[UIBarButtonItem alloc]initWithCustomView:forkButton];
    UIBarButtonItem*item= [[UIBarButtonItem alloc]initWithCustomView:leftButton];
    
    self.navigationItem.leftBarButtonItem=item;
    self.navigationItem.rightBarButtonItem=item1;
}

#pragma mark 返回事件
-(void)comeBackToRoot{
    [self.navigationController popToRootViewControllerAnimated:YES];
}

-(void)comeBack{
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark 设置tableview
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.sendArray.count;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return ACTUAL_HEIGHT(70);
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return ACTUAL_HEIGHT(70);
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *BGView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, ACTUAL_HEIGHT(70))];
    BGView.backgroundColor=[UIColor whiteColor];
    
    UILabel *titleLabel=[[UILabel alloc]initWithFrame:CGRectMake(ACTUAL_WIDTH(20), ACTUAL_HEIGHT(15), ACTUAL_WIDTH(320), ACTUAL_HEIGHT(40))];
    titleLabel.text=@"SHIPMENT METHOD:\n(It can make fastest arrive)";
    titleLabel.numberOfLines = 0 ;
    titleLabel.font=[UIFont systemFontOfSize:14];
    [BGView addSubview:titleLabel];
    
    return BGView;
}

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell*cell=[tableView dequeueReusableCellWithIdentifier:@"666"];
    if (!cell) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"666"];
    }
//    cell.backgroundColor=[UIColor yellowColor];
    cell.selectionStyle=UITableViewCellSelectionStyleNone;
    
    UILabel *titleLabel=[[UILabel alloc]initWithFrame:CGRectMake(ACTUAL_WIDTH(20), ACTUAL_HEIGHT(15), ACTUAL_WIDTH(200), ACTUAL_HEIGHT(40))];
//    titleLabel.backgroundColor=[UIColor redColor];
    titleLabel.text=self.sendArray[indexPath.row][@"title"];
    [cell addSubview:titleLabel];
    
    UILabel *costLabel=[[UILabel alloc]initWithFrame:CGRectMake(ACTUAL_WIDTH(230), ACTUAL_HEIGHT(15), ACTUAL_WIDTH(120), ACTUAL_HEIGHT(40))];
//    costLabel.backgroundColor=[UIColor blueColor];
    costLabel.textAlignment=2;
    costLabel.font=[UIFont systemFontOfSize:20];
    costLabel.text=self.sendArray[indexPath.row][@"cost"];
    [cell addSubview:costLabel];
    
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if ([self.delegate respondsToSelector:@selector(cellOfTransMethodSelected:AndTitle:andShipPrice:)]) {
        
        [self.delegate cellOfTransMethodSelected:self.sendArray[indexPath.row][@"id"]
                                        AndTitle:self.sendArray[indexPath.row][@"title"]
                                    andShipPrice:self.sendArray[indexPath.row][@"cost"]];
    }
    [[SlideNavigationController sharedInstance] popViewControllerAnimated:YES];
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
